//
//  Common.swift
//  AliBaiChuan
//
//  Created by 郑东喜 on 2017/2/9.
//  Copyright © 2017年 郑东喜. All rights reserved.
//

import UIKit

// MARK:- 首页URL
let _shouyeURL = "https://h5.m.taobao.com"

let SW = UIScreen.main.bounds.width
let SH = UIScreen.main.bounds.height

// MARK:- uiview分类扩展
extension UIView {
    
    var LeftX: CGFloat {
        get {
            return self.frame.origin.x
        }
    }
    var RightX: CGFloat {
        get {
            return self.frame.origin.x + self.bounds.width
        }
    }
    var TopY: CGFloat {
        get {
            return self.frame.origin.y
        }
    }
    var BottomY: CGFloat {
        get {
            return self.frame.origin.y + self.bounds.height
        }
    }
    var Width: CGFloat {
        get {
            return self.bounds.width
        }
    }
    var Height: CGFloat {
        get {
            return self.bounds.height
        }
    }
    
}

///数组淘宝
let _tbArray : NSMutableArray = NSMutableArray()

///登陆状态
let _loginInfo : NSArray = NSArray()

///本地存储
let localSave = UserDefaults.standard


/// 提示框
///
/// - Parameter data: 提示的信息
func showWithAlert(data:String) -> Void {
    ///提示框显示结果
    let alertVc = UIAlertController.init(title: "用户信息", message: data, preferredStyle: .alert)
    alertVc.addAction(UIAlertAction.init(title: "确定", style: .default, handler: nil))
    
    UIApplication.shared.keyWindow?.rootViewController?.present(alertVc, animated: true, completion: nil)
}

// MARK:- 颜色扩展
extension UIColor {
    
    /**
     快速构建rgb颜色
     
     - parameter r: r
     - parameter g: g
     - parameter b: b
     
     - returns: 返回rgb颜色对象，alpha默认1
     */
    class func colorWithRGB(_ r: CGFloat, g: CGFloat, b: CGFloat) -> UIColor
    {
        return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: 1)
    }
    
    /**
     生成随机颜色
     
     - returns: 返回随机色
     */
    class func randomColor() -> UIColor
    {
        let r = CGFloat(arc4random_uniform(256))
        let g = CGFloat(arc4random_uniform(256))
        let b = CGFloat(arc4random_uniform(256))
        return UIColor.colorWithRGB(r, g: g, b: b)
    }
    
}
